<?php 


/** 
***************************************************
*欢迎使用免费版xSite企业自助建站软件！
*这是一个专业为搜索引擎营销而设计的，极稳定、极易维护的建站软件！
*官方客服：help@php.net.cn
*官方下载网址：http://www.php.net.cn/xsite/ 
***************************************************
**/




if(!defined('IN_SITETEAM')) { exit('Access Denied'); } function message($URL, $msg = null, $window = "this"){ include SITE_ROOT . "/admin/tpl/message.tpl.php"; exit(); } function dynamic_form($array, $layout = 'table') { global $site_url; $formstr = ''; if (is_array($array) && count($array) > 0) foreach ($array as $k => $v) { if (!array_key_exists('form', $v)) continue; if ($v['form'] == 'input') { if (!array_key_exists('type', $v)) continue; if ($v['type'] == 'text') { $temp = '<label>'; $temp .= '<input name="data[' . ($k) . ']" type="text" id="' . ($k) . '" '; $temp .= 'value="' . ((!empty($v['value']))?$v['value']:'') . '" '; $temp .= 'class="' . ((!empty($v['class']))?$v['class']:'') . '" '; $temp .= 'style="' . ((!empty($v['width']))?"width:{$v['width']};":'') . ' ' . ((!empty($v['height']))?"height:{$v['height']};":'') . '"'; $temp .= '>'; $temp .= '</label>'; if ($layout == 'table') { $formstr .= "\n\n" . '<tr><td class="form_left_space">' . ((!empty($v['name']))?$v['name']:'&nbsp;') . '</td><td class="form_right_space">'. $temp . '</td><td>&nbsp;&nbsp;' . ((!empty($v['description']))?$v['description']:'&nbsp;') . '&nbsp;&nbsp;</td></tr>' . "\n\n"; } elseif ($layout == 'list') { $formstr .= "\n\n" . '<tr><th>' . ((!empty($v['name']))?$v['name']:'&nbsp;') . '<span style="margin-left:20px;font-weight: lighter;font:12px;color: #CCCCCC;">' . ((!empty($v['description']))?"[".$v['description']."]":'&nbsp;') . '</span></th></tr><tr><td>'. $temp . '</td></tr>' . "\n\n"; } } if ($v['type'] == 'radio') { $temp = ''; if (is_array($v['list']) && count($v['list'])) { foreach ($v['list'] as $kk => $vv) { $temp .= '<label>'; $temp .= '<input name="data[' . ($k) . ']" type="radio" id="' . ($k . $kk) . '" '; $temp .= 'value="' . ($kk) . '" '; $temp .= 'class="' . ((!empty($v['class']))?$v['class']:'') . '" '; $temp .= 'style="' . ((!empty($v['width']))?"width:{$v['width']};":'') . ' ' . ((!empty($v['height']))?"height:{$v['height']};":'') . '"'; if (isset($v['value']) && array_key_exists($v['value'], $v['list']) && $v['value'] == $kk) { $temp .= ' checked>'; } else { $temp .= '>'; } $temp .= $vv; $temp .= '</label>'; } } if ($layout == 'table') { $formstr .= "\n\n" . '<tr><td class="form_left_space">' . ((!empty($v['name']))?$v['name']:'&nbsp;') . '</td><td class="form_right_space">'. $temp . '</td><td>&nbsp;&nbsp;' . ((!empty($v['description']))?$v['description']:'&nbsp;') . '&nbsp;&nbsp;</td></tr>' . "\n\n"; } elseif ($layout == 'list') { $formstr .= "\n\n" . '<tr><th>' . ((!empty($v['name']))?$v['name']:'&nbsp;') . '<span style="margin-left:20px;font-weight: lighter;font:12px;color: #CCCCCC;">' . ((!empty($v['description']))?"[".$v['description']."]":'&nbsp;') . '</span></th></tr><tr><td>'. $temp . '</td></tr>' . "\n\n"; } } if ($v['type'] == 'checkbox') { } if ($v['type'] == 'file') { '<input type="file" name="file">'; $temp = '<label>'; $temp .= '<input name="' . ($k) . '" type="file" id="' . ($k) . '" '; $temp .= 'class="' . ((!empty($v['class']))?$v['class']:'') . '" '; $temp .= 'style="' . ((!empty($v['width']))?"width:{$v['width']};":'') . ' ' . ((!empty($v['height']))?"height:{$v['height']};":'') . '"'; $temp .= '>'; $temp .= '</label>'; $temp .= "<label><input name='data[{$k}]' id='hidden_{$k}' type='hidden' value='" . ((!empty($v['value']))?$v['value']:'') . "' /></label>" . ((!empty($v['value'])) ? "<label>&nbsp;&nbsp;<b><a target='_blank' rel='lightbox[roadtrip]' href='http://{$site_url}" . SITE_PATH . "/{$v['value']}'>查看已上传文件</a></b>&nbsp;&nbsp;<input name='del_file[{$k}]' type='checkbox' value='{$v['value']}'>&nbsp;删除它</label>" : ''); if ($layout == 'table') { $formstr .= "\n\n" . '<tr><td class="form_left_space">' . ((!empty($v['name']))?$v['name']:'&nbsp;') . '</td><td class="form_right_space">'. $temp . '</td><td>&nbsp;&nbsp;' . ((!empty($v['description']))?$v['description']:'&nbsp;') . '&nbsp;&nbsp;</td></tr>' . "\n\n"; } elseif ($layout == 'list') { $formstr .= "\n\n" . '<tr><th>' . ((!empty($v['name']))?$v['name']:'&nbsp;') . '<span style="margin-left:20px;font-weight: lighter;font:12px;color: #CCCCCC;">' . ((!empty($v['description']))?"[".$v['description']."]":'&nbsp;') . '</span></th></tr><tr><td>'. $temp . '</td></tr>' . "\n\n"; } } } if ($v['form'] == 'select') { } if ($v['form'] == 'textarea') { $temp = '<label>'; $temp .= '<textarea name="data[' . ($k) . ']" id="' . ($k) . '" '; $temp .= 'class="' . ((!empty($v['class']))?$v['class']:'') . '" '; $temp .= 'style="' . ((!empty($v['width']))?"width:{$v['width']};":'') . ' ' . ((!empty($v['height']))?"height:{$v['height']};":'') . '"'; $temp .= '>'; $temp .= ((!empty($v['value']))?$v['value']:''); $temp .= '</textarea>'; $temp .= '</label>'; if ($layout == 'table') { $formstr .= "\n\n" . '<tr><td class="form_left_space">' . ((!empty($v['name']))?$v['name']:'&nbsp;') . '</td><td class="form_right_space">'. $temp . '</td><td>&nbsp;&nbsp;' . ((!empty($v['description']))?$v['description']:'&nbsp;') . '&nbsp;&nbsp;</td></tr>' . "\n\n"; } elseif ($layout == 'list') { $formstr .= "\n\n" . '<tr><th>' . ((!empty($v['name']))?$v['name']:'&nbsp;') . '<span style="margin-left:20px;font-weight: lighter;font:12px;color: #CCCCCC;">' . ((!empty($v['description']))?"[".$v['description']."]":'&nbsp;') . '</span></th></tr><tr><td>'. $temp . '</td></tr>' . "\n\n"; } } if ($v['form'] == 'system') { if ($v['type'] == 'category') { $temp = '<label>'; $temp .= "\r\n" . '<select name="data[' . ($k) . ']" id="' . ($k) . '" '; $temp .= 'class="' . ((!empty($v['class']))?$v['class']:'') . '" '; $temp .= 'style="' . ((!empty($v['width']))?"width:{$v['width']};":'') . ' ' . ((!empty($v['height']))?"height:{$v['height']};":'') . '"'; $temp .= '>'; $temp .= "\r\n" . '<option value="0">--请选择--</option>'; $category = &$GLOBALS['system_tree_category']; if (isset($v['module']) && !empty($v['module'])) { foreach ($category as $m => $n) { if ($v['module'] == $n['module']) { $temp .= "\r\n" . '<option value="' . $m . '" ' . (!empty($v['value']) && $v['value'] == $m ? 'selected="selected"' : '') . '>' . $n['name'] . '</option>'; } if (is_array($n['subcategory']) && count($n['subcategory']) ) { foreach ($n['subcategory'] as $mm => $nn) { if ($v['module'] == $nn['module']) { $temp .= "\r\n" . '<option value="' . $mm . '" ' . (!empty($v['value']) && $v['value'] == $mm ? 'selected="selected"' : '') . '>&nbsp;&nbsp;|----' . $nn['name'] . '</option>'; } if (is_array($nn['subcategory']) && count($nn['subcategory']) ) { foreach ($nn['subcategory'] as $mmm => $nnn) { if ($v['module'] == $nnn['module']) { $temp .= "\r\n" . '<option value="' . $mmm . '" ' . (!empty($v['value']) && $v['value'] == $mmm ? 'selected="selected"' : '') . '>&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;|----' . $nnn['name'] . '</option>'; } } } } } } } else { foreach ($category as $m => $n) { $temp .= "\r\n" . '<option value="' . $m . '" ' . (!empty($v['value']) && $v['value'] == $m ? 'selected="selected"' : '') . '>' . $n['name'] . '</option>'; if (is_array($n['subcategory']) && count($n['subcategory']) ) { foreach ($n['subcategory'] as $mm => $nn) { $temp .= "\r\n" . '<option value="' . $mm . '" ' . (!empty($v['value']) && $v['value'] == $mm ? 'selected="selected"' : '') . '>&nbsp;&nbsp;|----' . $nn['name'] . '</option>'; if (is_array($nn['subcategory']) && count($nn['subcategory']) ) { foreach ($nn['subcategory'] as $mmm => $nnn) { $temp .= "\r\n" . '<option value="' . $mmm . '" ' . (!empty($v['value']) && $v['value'] == $mmm ? 'selected="selected"' : '') . '>&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;|----' . $nnn['name'] . '</option>'; } } } } } } $temp .= '</label>'; if ($layout == 'table') { $formstr .= "\n\n" . '<tr><td class="form_left_space">' . ((!empty($v['name']))?$v['name']:'&nbsp;') . '</td><td class="form_right_space">'. $temp . '</td><td>&nbsp;&nbsp;' . ((!empty($v['description']))?$v['description']:'&nbsp;') . '&nbsp;&nbsp;</td></tr>' . "\n\n"; } elseif ($layout == 'list') { $formstr .= "\n\n" . '<tr><th>' . ((!empty($v['name']))?$v['name']:'&nbsp;') . '<span style="margin-left:20px;font-weight: lighter;font:12px;color: #CCCCCC;">' . ((!empty($v['description']))?"[".$v['description']."]":'&nbsp;') . '</span></th></tr><tr><td>'. $temp . '</td></tr>' . "\n\n"; } } } } return $formstr; } function update_index($category = '') { global $site_id, $user_data_dir, $site_url; if (empty($site_url)) { return false; } global $_Db_Conf; if (!isset($GLOBALS['db'])) { $db = new db_mysql(); } else { $db = &$GLOBALS['db']; } $system_category = get_sys_category($site_url); if ($category != '') { if (array_key_exists($category, $system_category)) { $temp = $system_category[$category]; $system_category = array(); $system_category[$category] = $temp; } else { return false; } } if (is_array($system_category) && count($system_category)) { foreach ($system_category as $category => $info) { if ($info['module'] == 'article') { $db->delete("{$site_id}_article", "category = '{$category}'"); $category_dir = $user_data_dir . "/{$category}"; if (!file_exists($category_dir)) { continue; } $article_list = array(); if ($handle = opendir($category_dir)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && substr($file, -4, 4) == '.txt') { $key = substr($file, 0, -4); if (file_exists("{$category_dir}/{$file}")) { $article_list[$key] = read_array_file("{$category_dir}/{$file}"); $article_list[$key]['key'] = $key; } } } closedir($handle); if (is_array($article_list) && count($article_list)) { ksort($article_list); foreach ($article_list as $key => $v) { $article_info = $v; $data = array(); $data['key'] = $key; $data['category'] = $category; $data['body_name'] = (!empty($article_info['body_name']) ? $article_info['body_name'] : ''); $data['ptitle'] = (!empty($article_info['ptitle']) ? $article_info['ptitle'] : ''); $data['status'] = (!empty($article_info['status']) ? $article_info['status'] : '1'); $data['is_first'] = (!empty($article_info['is_first']) ? $article_info['is_first'] : '1'); if ($db->insert("{$site_id}_article", $data)) { ; } } } } else { } } if ($info['module'] == 'product') { $db->delete("{$site_id}_product", "category = '{$category}'"); $category_dir = $user_data_dir . "/{$category}"; if (!file_exists($category_dir)) { continue; } $product_list = array(); if ($handle = opendir($category_dir)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && substr($file, -4, 4) == '.txt') { $key = substr($file, 0, -4); if (file_exists("{$category_dir}/{$file}")) { $product_list[$key] = read_array_file("{$category_dir}/{$file}"); $product_list[$key]['key'] = $key; } } } closedir($handle); if (is_array($product_list) && count($product_list)) { ksort($product_list); foreach ($product_list as $key => $v) { $product_info = $v; $data = array(); $data['key'] = $key; $data['category'] = $category; $data['name'] = (!empty($product_info['name']) ? $product_info['name'] : ''); $data['ptitle'] = (!empty($product_info['ptitle']) ? $product_info['ptitle'] : ''); $data['pname'] = (!empty($product_info['pname']) ? $product_info['pname'] : ''); $data['pass'] = (!empty($product_info['pass']) ? $product_info['pass'] : '4'); $data['status'] = (!empty($product_info['status']) ? $product_info['status'] : '1'); if ($db->insert("{$site_id}_product", $data)) { ; } } } } else { } } } } return true; } function check_db_structure($site_id) { global $_Db_Conf; if (!isset($GLOBALS['db'])) { $db = new db_mysql(); } else { $db = &$GLOBALS['db']; } if (empty($site_id)) { return false; } $db->query("SHOW TABLES;"); $temp = $db->fetchAll(); if (is_array($temp) && count($temp)) { foreach ($temp as $k => $v) { $db_table[] = $v["Tables_in_{$_Db_Conf['dbname']}"]; } } else { $db_table = array(); } if (!in_array("{$site_id}_article", $db_table)) { $SQL = "CREATE TABLE IF NOT EXISTS `{$site_id}_article` (
				  `key` int(10) unsigned NOT NULL,
				  `category` char(64) NOT NULL,
				  `body_name` varchar(255) NOT NULL,
				  `ptitle` varchar(255) NOT NULL,
				  `status` tinyint(1) NOT NULL,
				  `is_first` tinyint(1) NOT NULL,
				  PRIMARY KEY (`key`),
				  UNIQUE KEY `key` (`key`)
				) ENGINE=MyISAM DEFAULT CHARSET=utf8;"; $db->query($SQL); } if (!in_array("{$site_id}_product", $db_table)) { $SQL = "CREATE TABLE IF NOT EXISTS `{$site_id}_product` (
				  `key` int(10) unsigned NOT NULL,
				  `category` char(64) NOT NULL,
				  `name` varchar(255) NOT NULL,
				  `ptitle` varchar(255) NOT NULL,
				  `pname` varchar(255) NOT NULL,
				  `pass` tinyint(1) NOT NULL,
				  `status` tinyint(1) NOT NULL,
				  PRIMARY KEY (`key`),
				  UNIQUE KEY `key` (`key`)
				) ENGINE=MyISAM DEFAULT CHARSET=utf8;"; $db->query($SQL); } return true; } function str_num2char($number) { $n = array('1', '2', '3', '4', '5', '6', '7', '8', '9', '0'); $c = array('!', '@', '#', '$', '%', '^', '&', '*', '(', ')'); return str_replace($n, $c, "{$number}"); } function save_array_to_file($array, $arrayfile, $arrayname) { if (!is_array($array) || empty($arrayfile) || empty($arrayname)) { return false; } $fp = fopen($arrayfile, "w"); $cachetext = "\n<?php\n"; $cachetext .= "if(!defined('IN_SITETEAM')) {exit('Access Denied');}\n"; $cachetext .= "\${$arrayname}= \n" . var_export($array, true) . ";\n"; $cachetext .= "?>\n"; fwrite($fp, $cachetext); fclose($fp); return true; } function file_del_dir($dir) { if (!file_exists("{$dir}")) { return false; } if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { if (is_dir("{$dir}/{$file}")) { if (!@rmdir("{$dir}/{$file}")) { file_del_dir("{$dir}/{$file}"); } else { ; } } else { @unlink("{$dir}/{$file}"); } } } closedir($handle); } @rmdir($dir); } function xsite_update_zip() { $remote_zip = ''; if (function_exists('get_headers')) { $remote_info = get_headers(Data_API('/xsite/download.php'), 1); if (isset($remote_info['Location']) && !empty($remote_info['Location'])) { $remote_zip = $remote_info['Location']; } } if ($remote_zip == '') { $remote_zip = @file_get_contents(Data_API('/xsite/download.php?file=xsite')); } if ($remote_zip == '') { $remote_zip = Data_API('/xsite/xsite.zip'); } return $remote_zip; } function upload_images($uploadname, $image_save_path, $watermark = 1) { $image_info = array(); $handle = new Upload($_FILES[$uploadname]); if (!$handle->file_is_image) { return $image_info; } if ($handle->uploaded) { $handle->dir_auto_create = true; $handle->file_overwrite = false; $handle->file_auto_rename = true; $handle->dir_auto_chmod = true; $handle->dir_chmod = 0777; $handle->allowed = array('image/jpeg', 'image/gif', 'image/png'); $handle->jpeg_quality = 100; if ($handle->image_src_x > 300 && $watermark == 1 && file_exists(SITE_WATERMARK) ) { $handle->image_watermark = SITE_WATERMARK; $handle->image_watermark_position = SITE_WATERMARK_POSITION; $handle->image_watermark_x = 50; $handle->image_watermark_y = 50; } $handle->file_new_name_body = preg_replace('/[\W]+/i', '_', $handle->file_src_name_body); $handle->Process($image_save_path); if ($handle->processed) { $image_info['path'] = preg_replace('/[\/]+/i', '/', str_replace('\\', '/', $handle->file_dst_path)); $image_info['name_body'] = $handle->file_dst_name_body; $image_info['name_ext'] = $handle->file_dst_name_ext; $image_info['name'] = $handle->file_dst_name; return $image_info; } else { return false; } $handle-> Clean(); } else { return false; } return $image_info; } function upload_multiple_images($uploadname, $image_save_path, $watermark = 1) { if (empty($uploadname) || empty($image_save_path)) { return false; } $upload_list = array(); $files = array(); foreach ($_FILES[$uploadname] as $k => $l) { foreach ($l as $i => $v) { if (!array_key_exists($i, $files)) $files[$i] = array(); $files[$i][$k] = $v; } } foreach ($files as $key => $file) { $handle = new upload($file, 'zh_CN'); $handle->dir_auto_create = true; $handle->file_overwrite = false; $handle->file_auto_rename = true; $handle->dir_auto_chmod = true; $handle->dir_chmod = 0777; $handle->allowed = array('image/jpeg', 'image/gif', 'image/png'); $handle->jpeg_quality = 100; if ($handle->image_src_x > 300 && $watermark == 1 && file_exists(SITE_WATERMARK) ) { $handle->image_watermark = SITE_WATERMARK; $handle->image_watermark_position = SITE_WATERMARK_POSITION; $handle->image_watermark_x = 50; $handle->image_watermark_y = 50; } $handle->file_new_name_body = preg_replace('/[\W]+/i', '_', $handle->file_src_name_body); if ($handle->uploaded) { if ($handle->image_src_x > 1200) { $handle->image_resize = true; $handle->image_ratio = true; $handle->image_ratio_y = true; $handle->image_x = 1200; } $handle->Process($image_save_path); if ($handle->processed) { $upload_list[$key]['path'] = preg_replace('/[\/]+/i', '/', str_replace('\\', '/', $handle->file_dst_path)); $upload_list[$key]['name_body'] = $handle->file_dst_name_body; $upload_list[$key]['name_ext'] = $handle->file_dst_name_ext; $upload_list[$key]['name'] = $handle->file_dst_name; } else { ; } $handle-> Clean(); } else { } } return $upload_list; } function get_html_images($html, $savepath) { global $site_url; if (empty($savepath) || !file_exists($savepath)) { return $text; } $remote_file = array(); if (preg_match_all('/src=[\'|"]+([^\'"]+\.[jpg|gif|png|jpeg]+)[\'|"]+/is', $html, $temp)) { $temp = $temp[1]; if (is_array($temp) && count($temp)) { foreach ($temp as $v) { if (preg_match('/^http:\/\//is', $v)) { if (!preg_match('/^http:\/\/' . preg_quote($site_url) . '/is', $v)) { $remote_file[md5($v)] = $v; } } } } } if (is_array($remote_file) && count($remote_file)) { $date_dir = date("Ymd", time()); if(!file_exists("{$savepath}/{$date_dir}")) mkdir("{$savepath}/{$date_dir}"); foreach ($remote_file as $k => $v) { $fileinfo = pathinfo($v); $filename = "{$savepath}/{$date_dir}/{$k}.{$fileinfo['extension']}"; if ($image_file = @file_get_contents($v)) { $fp = fopen($filename, "w"); fwrite($fp, $image_file); fclose($fp); $images = @getimagesize($filename); if ($images != false) { if (is_array($images) && in_array($images['mime'], array("image/pjpeg", "image/gif", "image/jpeg", "image/png", "image/jpg"))) { $filename = str_replace(SITE_DIR . '/', '', $filename); $html = str_replace($v, $filename, $html); } else { @unlink($filename); } } else { @unlink($filename); } } } return $html; } else { return $html; } } ?>